package com.qwc.blog.config;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import com.qwc.blog.common.constant.CommonConstant;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author qiuwencong
 * @Date 2022/1/24 15:19
 * @Package com.qwc.blog.config
 * @Description
 */
@Data
@Slf4j
@Configuration
public class CustomizerCacheConfig {

    @Value("${qwc.cache.expire}")
    private int expireTime;

    @Value("${qwc.cache.check}")
    private int checkInterval;

    @Bean
    public TimedCache<String, String> timedCache(){
        TimedCache<String, String> cache = CacheUtil.newTimedCache(expireTime);
        if (expireTime>CommonConstant.ZERO) {
            cache.schedulePrune(checkInterval);
        }
        log.info("自定义缓存过期时间：{}",expireTime);
        log.info("自定义缓存定时清理：{}",checkInterval);
        return cache;
    }

}
